#include "Logic.h"

Logic::Logic(){
}
Logic::Logic(string command){
	commandString=command;
	processor=NULL;
}
Logic::~Logic(){
	//delete processor;
}
void Logic::getCommand(string command){
	commandString=command;
}
void Logic::processCommand(){
	/*string command;
	string content;
	command=takeFirstWord(commandString);
	content=takeContent(commandString,command);
	commandType type;
	type=detectCommandType(command);
	solveTheCommand(type,content);*/
	processor=pass.processCommand(commandString,&allTask,&allCmdStack);
	processor->HandleProcesss();
	resultList=allTask.getDisplayedList();
	delete processor;
}

/*void Logic::solveTheCommand(commandType type,string content){
	switch(type){
	case Add:
		processor=new AddProcess(content,&allTask);
		
		break;
	case Delete:
		processor=new DeleteProcess(content,&allTask);
		//processor->HandleProcesss();
		break;
	case Undo:
		break;
	case Redo:
		break;
	case Search:
		break;
	case Select:
		break;
	case Update:
		processor=new UpdateProcess(content,&allTask);
		//processor->HandleProcesss();
		break;
	case Exit:
		break;
	default:
		break;

	}
	processor->HandleProcesss();
}
string Logic::takeFirstWord(string tmp){
	string result;
	for (int i=0;i<tmp.length();i++){
		if (tmp[i]==' ')
			break;
		else
			result+=tmp[i];
	}
	return result;
}
string Logic::takeContent(string commandString,string command){
	string result;
	int commandLength=0;
	int cmdLength=0;
	commandLength=command.length();
	cmdLength=commandString.length();
	if (commandLength<cmdLength){
		result=commandString.substr(commandLength+1,cmdLength-commandLength-1);//exculde the space
	}else
		result=command;
	return result;
}
commandType Logic::detectCommandType(string command){
	commandType result=Search;

	if (command==ADD)
		result=Add;
	if (command==DELETE)
		result=Delete;
	if (command==EDIT)
		result=Edit;
	if (command==UDATE)
		result=Update;
	if (command==UNDO)
		result=Undo;
	if (command==REDO)
		result=Redo;
	if (command==EXIT)
		result=Exit;

	return result;
}
void Logic::setCommandString(string cmdStr){
	commandString=cmdStr;
}*/
LogicProcess* Logic::getProcessor(){
	return processor;
}
allTaskList Logic::getAllTask(){
	return allTask;
}
TaskList Logic::getResultList(){
	return resultList;
}